home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000206_icon-group-sender _Mon Aug 15 15:55:47 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  6KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 15 Aug 1994 14:01:26 MST
  2. To: icon-group-l@cs.arizona.edu
  3. Date: 15 Aug 1994 15:55:47 GMT
  4. From: espie@basilic.ens.fr (Marc Espie)
  5. Message-Id: <32o363$lo6@nef.ens.fr>
  6. Organization: Ecole Normale Superieure, PARIS, France
  7. Sender: icon-group-request@cs.arizona.edu
  8. References: <MBERGER.94Aug11084252@mbsdev24.lehman.com>, <1994Aug13.213550.26432@netlabs.com>
  9. Subject: Re: Generators
  10. Status: R
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. In article <1994Aug13.213550.26432@netlabs.com>,
  14. Larry Wall <lwall@netlabs.com> wrote:
  15. >In article <MBERGER.94Aug11084252@mbsdev24.lehman.com> mberger@mbsdev24.lehman.com (Micha Berger) writes:
  16. >: Icon has a concept of generator. It's been a while since I last used Icon,
  17. >: but here's the basic concept in an ad-hoc Perl-like syntax.
  18. >: 
  19. >: Generators are functions/operators that return a sequence of values. For
  20. >: example, index(/re/, $string) could return the first location of /re/ in
  21. >: $string, followed by the second, followed by the third...
  22. >
  23. >More specifically, generators can, on demand, return the next answer in a
  24. >sequence of potential answers.
  25. >
  26. >: There are two ways this is used. The first is that if an expression "fails", it
  27. >: can be reevaluated using the next value: e.g.
  28. >:     $loc = index(/re/, $string) > 32;
  29. >: will set $loc to a location greater than 32, or, undef.
  30. >
  31. >Just out of curiosity, what prevents it from returning the *next*
  32. >location greater than 32 the next time you evaluate it?  Is there an
  33. >implicit cut operation?
  34.  
  35. Implicit ? no... explicit, yes, and it's not a dirty concept like in Prolog
  36. for instance, but perfectly clean, based upon syntactic entities.
  37.  
  38. In that particular case, instantiation does cut the backtracking. In icon,
  39. you write:
  40. loc := 32 < find(s1, s2)
  41. because:
  42. - <, when it succeeds, returns the expression on the LEFT, not the right
  43. (which is reasonable, since it allows for 0 < i < 10)
  44. - := is the normal instantiation operator. There also exists a reversible
  45. one (<-) which you use VERY rarely.
  46. - the backtracking would be cut at the end of the expression anyway. EVERY
  47. expression is closed for backtracking. And there are other control points where
  48. backtracking can not occur.
  49.  
  50. >
  51. >: The other is an "every" iterator:
  52. >:     every(index(/re/, $string)) {
  53. >:         ...
  54. >:     }
  55. >: 
  56. >: (One neat little feature, it meant that || could be read to mean "concatenate
  57. >: two sequences" and still retain its current functionality.)
  58. >
  59. >Well, yes, depending on what's demanded by the context.  Perl has a
  60. >simpler demand structure than Icon, and people still complain about it.
  61. >
  62. >: I was wondering if there is some easy way to get similar functionality out of
  63. >: Perl.
  64. >
  65. >Yes and no.  There are a few operators in Perl that behave like
  66. >generators in scalar context, such as <> and m//g.  And it's easy
  67. >enough to write functions that remember their state and return the
  68. >"next" thing.  But the state is explicit, and doesn't differentiate who
  69. >called the function (unless you're really sneaky).  And lists in Perl
  70. >are always completely constructed before they are passed on to the next
  71. >processing element.
  72.  
  73. In Icon, you differentiate the other way. The implicit state differentiates
  74. where the function was called. If you want an expression that can be resumed
  75. elsewhere, you encapsulate it into a coexpression. Here is the classic 
  76. `build identifiers on the fly' in Icon.
  77. procedure newid
  78.     i := 0
  79.     repeat
  80.         {
  81.         i +:= 1
  82.         suspend "a"||i
  83.         }
  84. end
  85.  
  86. called thus:
  87. gen := create newid()
  88. id:= @gen
  89. each time you wish for a new id.
  90.  
  91.  
  92. and that way, you can avoid constructing some lists on the fly, which is
  93. *sometimes* a win.
  94.  
  95. >
  96. >I basically don't like languages that try to help you by keeping track
  97. >of a lot of implicit state.  I don't think most ordinary folks like
  98. >them either.  Regular expressions are already dangerously close to the
  99. >limits of mortal endurance, which is why the use of them in Perl is
  100. >rigidly circumscribed.  I'm somewhat allergic to the rampant uncertainty
  101. >engendered by pervasive implicit backtracking.  (I have similar feelings
  102. >about the way shells do pervasive string interpolation.)  Perl is very
  103. >much a what-you-see-is-what-it-does language.  When you're fighting with
  104. >one of the good ol' boys, just stand up straight and start boxing...
  105.  
  106. There is no pervasive implicit backtracking in Icon, it's very well-bounded
  107. and works just like an ordinary sequential language, except where you NEED
  108. backtracking.
  109.  
  110. I'd contend Icon is almost in the same league as Perl. After all, you don't
  111. see behind the scene garbage-collecting in Perl either.
  112.  
  113. >
  114. >Like all forms of abstraction, generators are a mixed blessing.
  115. >Icon's popularity stems directly from its abstraction facilities.
  116. >Unfortunately, so does its *lack* of popularity.
  117.  
  118. I don't know, it seems to me that nobody is particularly pushing Icon these
  119. days... and it tends to be a lot bigger than perl, and a trifle slower and 
  120. not to be aimed at the same goals... not the same concision as far as work
  121. on regular expressions go, but much more powerful for many other problems
  122. dealing with string analysis (Icon doesn't have regular expressions...)
  123. >
  124. >That's just my $.02 worth (multiplied, of course, by however many more
  125. >subsribers there are to comp.lang.perl than to comp.lang.icon).
  126. >
  127. >Larry
  128.  
  129. I've taken upon myself to crosspost this to comp.lang.icon where lots of nice
  130. guys will be able to give a better analysis of all this than me.
  131.  
  132. Oh, and by the way, I use regularly Icon AND Perl, not for quite the same
  133. problems, obviously.
  134.  
  135.  
  136. -- 
  137. [nosave]<http://acacia.ens.fr:8080/home/espie/index.html>
  138. `Ayuka no koto... suki dayo.' (KOR, Ano Hi ni kaeritai)
  139. `$@0>@n(J $@$N$3$H!<9%$-$@$h!#(J' ($@$"$NF|$K5"$j$?$$(J)(B
  140.     Marc Espie (Marc.Espie@ens.fr)
  141.